package com.ddl.service.impl;

import com.ddl.dao.MoneyRecordMapper;
import com.ddl.pojo.MoneyRecord;
import com.ddl.service.MoneyRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;

/**
 * @author: liyuxiang
 * @create: 2018-12-11
 */
@Service
public class MoneyRecordServiceImpl implements MoneyRecordService {

    @Autowired
    MoneyRecordMapper moneyRecordMapper;

    @Override
    public void consumer(int userId, BigDecimal total, String cause) {
        MoneyRecord moneyRecord = new MoneyRecord();
        moneyRecord.setUserId(userId);
        moneyRecord.setCause(cause);
        moneyRecord.setAmount(total);
        moneyRecord.setType(-1);
        moneyRecord.setCreateTime(new Date());
        moneyRecord.setUpdateTime(new Date());
        moneyRecordMapper.insert(moneyRecord);
    }

    @Override
    public void proveder(int userId, BigDecimal total, String cause) {
        MoneyRecord moneyRecord = new MoneyRecord();
        moneyRecord.setUserId(userId);
        moneyRecord.setCause(cause);
        moneyRecord.setAmount(total);
        moneyRecord.setType(1);
        moneyRecord.setCreateTime(new Date());
        moneyRecord.setUpdateTime(new Date());
        moneyRecordMapper.insert(moneyRecord);
    }
}
